package bookstudytest.date.newversion;

import java.time.*;
import java.time.temporal.TemporalAdjusters;

/**
 * @Author li.heng
 * @Date 2019/6/24 16
 * @Description: LocalDate 1.8版本新增的日期类
 **/
public class LocalDateDemo {
    public static void main(String[] args) {

        System.out.println(LocalDate.now().getYear());
    }

    public static String getDefaultDate() {
        // 获取指定zone现在的date
        String s = LocalDate.now(ZoneId.of("America/Chicago")).toString();
        // 获取当前地区现在的date
        String s1 = LocalDate.now().toString();
        // 获取当前zone现在的date
        LocalDate.now(Clock.systemDefaultZone());
        return s1;
    }

    public String withDayOfYear(int dayNum) {
        // 返回指定年份第dayNum天的日期
        LocalDate of = LocalDate.of(2019, 11, 24);
        return of.withDayOfYear(2).toString();
    }

    public String dateOfYMD(int year, int month, int day) {
        // 根据指定的年月日生成localDate
        LocalDate of = LocalDate.of(year, month, day);
        // 这里是把月份int用枚举值代替
        LocalDate of1 = LocalDate.of(year, Month.APRIL, day);
        // 1970-01-01加上Long类型参数的日期
        String s = LocalDate.ofEpochDay(356 * 10L).toString();
        // 获取本月的第一天日期
        LocalDate firstDay = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
        // 获取本月的最后一天
        LocalDate lastDay = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth());
        // 今天是本月几日
        int dayOfMonth = LocalDate.now().getDayOfMonth();
        // 今天是周几
        int value = LocalDate.now().getDayOfWeek().getValue();
        // 获取当前年份
        int year1 = LocalDate.now().getYear();
        // 获取当前月份
        int month1 = LocalDate.now().getMonth().getValue();
        return s;
    }
}
